import 'package:extended_tabs/extended_tabs.dart';
import 'package:flutter/material.dart';
import 'package:yp/config/style.dart';
import 'package:yp/pages/marketing/activity_declaration.dart';
import 'package:yp/pages/marketing/lucky_draw_list.dart';
import 'package:yp/pages/marketing/my_prize_list.dart';
import 'package:yp/pages/marketing/ranking_list.dart';
import 'package:yp/widgets/index.dart';

/// 活动说明 排行榜 我的奖品 获奖名单
class HelpLottery extends StatefulWidget {
  const HelpLottery({Key key}) : super(key: key);

  @override
  _HelpLotteryState createState() => _HelpLotteryState();
}

class _HelpLotteryState extends State<HelpLottery>
    with SingleTickerProviderStateMixin {
  // AnimationController _controller;
  TabController _controller;
  var _tabList = [
    Tab(text: '活动说明'),
    Tab(text: '排行榜'),
    Tab(text: '我的奖品'),
    Tab(text: '获奖名单')
  ];

  @override
  void initState() {
    super.initState();
    // _controller = AnimationController(vsync: this);
    // _controller.addListener(() {
    //   if (!_controller.indexIsChanging) {
    //     print(_controller.index);
    //   }
    // });
    _controller =
        TabController(initialIndex: 0, length: _tabList.length, vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: YPNavigationBar('助力摇奖'),
      body: Padding(
        padding: EdgeInsets.fromLTRB(
            12, 16, 12, MediaQuery.of(context).padding.bottom + 80),
        child: Column(
          children: [
            _tabHeadder(),
            _orderList(),
          ],
        ),
      ),
      backgroundColor: EsColors.Red,
    );
  }

  ///  tab栏切换的头部
  Widget _tabHeadder() {
    return ExtendedTabBar(
      tabs: List<Widget>.generate(
          _controller.length,
          (int index) => Container(
              width: MediaQuery.of(context).size.width / 4 - 10,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(10),
                    topRight: Radius.circular(10)),
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,

                  ///渐变色
                  colors: [Color(0xFFFFE4E6), Color(0xFFFFFFFF)],
                ),
              ),
              child: Center(child: _tabList[index]))),
      controller: _controller,
      labelPadding: EdgeInsets.only(top: 0, bottom: 0),
      labelColor: Color(0xff79050C),
      isScrollable: false,
      unselectedLabelColor: Color(0xffcd868a),
      indicatorSize: TabBarIndicatorSize.label,
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      indicatorWeight: 0,
      indicator: const ExtendedUnderlineTabIndicator(
          borderSide: BorderSide(color: Colors.white, width: 0)),
    );
  }

  /// 下边对应的列表
  Widget _orderList() {
    return Expanded(
      child: Container(
        decoration: BoxDecoration(
            color: EsColors.White,
            borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(10),
                bottomRight: Radius.circular(10))),
        child: TabBarView(controller: _controller, children: [
          ActivityDeclaration(),
          RankingList(),
          MyPrizeList(),
          LuckyDrawList(),
        ]),
      ),
    );
  }
}
